<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>研究生招生系统 - 研究生主管领导管理页面</title>
    {% load static %}
    <link rel="stylesheet" href="{% static 'css/styles.css' %}">
    <link rel="stylesheet" href="{% static 'plugins/bootstrap-5.3.0-alpha1-dist/css/bootstrap.min.css' %}">
    <script src="{% static 'plugins/bootstrap-5.3.0-alpha1-dist/js/bootstrap.bundle.min.js' %}"></script>
</head>
<body>
{% if error_msg %}
    <div class="alert alert-danger" role="alert">
        {{ error_msg }}
    </div>
{% endif %}
<nav class="navbar navbar-expand-lg navbar-light bg-light">
    <div class="container">
        <a class="navbar-brand" href="#">
            <img src="{% static 'img/bjfu.png' %}" alt="Bootstrap" width="252" height="61">
        </a>
        <h3 class="navbar-text ms-auto">北京林业大学研究生招生系统 - 研究生主管领导管理页面</h3>
    </div>
</nav>

<div class="container-fluid">
    <div class="row">
        <!-- 侧边导航栏 -->
        <div class="col-md-2 d-none d-md-block">
            <div class="sidebar">
                <nav>
                    <ul class="nav flex-column">
                        <li class="nav-item">
                            <a class="nav-link text-green" href="#" data-section="subjects" id="subjects-tab">学科信息</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-green" href="#" data-section="students" id="students-tab">考生信息</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-green" href="#" data-section="supervisors" id="supervisors-tab">导师信息</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-green" href="#" data-section="scores" id="scores-tab">考生初试信息</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-green" href="#" data-section="interviews" id="interviews-tab">考生复试信息</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-green" href="#" data-section="stutea" id="stutea-table-tab">师生双向选择信息</a>
                        </li>

                    </ul>
                </nav>
            </div>
        </div>
        <!-- 主内容区域 -->
        <div class="col-md-9">
            <div class="tab-content" id="myTabContent">
                <div class="tab-pane fade show active" id="subjects" role="tabpanel" aria-labelledby="subjects-tab">
                    <h2>学科信息</h2>
                    <div class="d-flex justify-content-between mb-3">
                        <button class="btn btn-success" id="add-subject-btn" data-bs-toggle="modal" data-bs-target="#addSubjectModal">增加科目</button>
                        <input type="text" id="search-input" class="form-control w-50" placeholder="搜索科目...">
                    </div>
                    <div class="card">
                        <div class="card-body">
                            <table class="table table-striped table-bordered">
                                <thead>
                                    <tr>
                                        <th>科目ID</th>
                                        <th>科目名称</th>
                                        <th>科目级别</th>
                                        <th>父科目</th>
                                        <th>科目概述</th>
                                        <th>科目类型</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody id="subjects-table-body">
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <!-- 编辑科目的模态框 -->
                    <div class="modal fade" id="editSubjectModal" tabindex="-1" aria-labelledby="editSubjectModalLabel" aria-hidden="true">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <h5 class="modal-title" id="editSubjectModalLabel">编辑科目</h5>
                                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                                </div>
                                <div class="modal-body">
                                    <form id="edit-subject-form">
                                        <input type="hidden" id="edit_subject_id">
                                        <div class="mb-3">
                                            <label for="edit_subject_name" class="form-label">科目名称</label>
                                            <input type="text" class="form-control" id="edit_subject_name" required>
                                        </div>
                                        <div class="mb-3">
                                            <label for="edit_subject_level" class="form-label">科目级别</label>
                                            <input type="text" class="form-control" id="edit_subject_level" required>
                                        </div>
                                        <div class="mb-3">
                                            <label for="edit_parent_subject" class="form-label">父科目</label>
                                            <input type="text" class="form-control" id="edit_parent_subject">
                                        </div>
                                        <div class="mb-3">
                                            <label for="edit_subject_overview" class="form-label">科目概述</label>
                                            <textarea class="form-control" id="edit_subject_overview"></textarea>
                                        </div>
                                        <div class="mb-3">
                                            <label for="edit_subject_type" class="form-label">科目类型</label>
                                            <input type="text" class="form-control" id="edit_subject_type" required>
                                        </div>
                                    </form>
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
                                    <button type="button" class="btn btn-primary" id="update-subject-btn">保存更改</button>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!-- 增加科目的模态框 -->
                    <div class="modal fade" id="addSubjectModal" tabindex="-1" aria-labelledby="addSubjectModalLabel" aria-hidden="true">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <h5 class="modal-title" id="addSubjectModalLabel">增加科目</h5>
                                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                                </div>
                                <div class="modal-body">
                                    <form id="add-subject-form">
                                        <div class="mb-3">
                                            <label for="subject_id" class="form-label">科目ID</label>
                                            <input type="text" class="form-control" id="subject_id" required>
                                        </div>
                                        <div class="mb-3">
                                            <label for="subject_name" class="form-label">科目名称</label>
                                            <input type="text" class="form-control" id="subject_name" required>
                                        </div>
                                        <div class="mb-3">
                                            <label for="subject_level" class="form-label">科目级别</label>
                                            <input type="text" class="form-control" id="subject_level" required>
                                        </div>
                                        <div class="mb-3">
                                            <label for="parent_subject" class="form-label">父科目</label>
                                            <input type="text" class="form-control" id="parent_subject">
                                        </div>
                                        <div class="mb-3">
                                            <label for="subject_overview" class="form-label">科目概述</label>
                                            <textarea class="form-control" id="subject_overview"></textarea>
                                        </div>
                                        <div class="mb-3">
                                            <label for="subject_type" class="form-label">科目类型</label>
                                            <input type="text" class="form-control" id="subject_type" required>
                                        </div>
                                    </form>
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
                                    <button type="button" class="btn btn-primary" id="save-subject-btn">保存</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="tab-pane fade" id="students" role="tabpanel" aria-labelledby="students-tab">
                    <h2>考生信息</h2>
                    <div class="d-flex justify-content-between mb-3">
                        <button class="btn btn-success" id="add-student-btn" data-bs-toggle="modal" data-bs-target="#addStudentModal">增加考生</button>
                        <input type="text" id="search-input-student" class="form-control w-50" placeholder="搜索考生...">
                    </div>
                    <div class="card">
                        <div class="card-body">
                            <table class="table table-striped table-bordered">
                                <thead>
                                    <tr>
                                        <th>学号</th>
                                        <th>姓名</th>
                                        <th>考号</th>
                                        <th>生源地</th>
                                        <th>本科专业</th>
                                        <th>本科学校</th>
                                        <th>邮箱</th>
                                        <th>电话</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody id="students-table-body">
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <!-- 增加考生的模态框 -->
                    <div class="modal fade" id="addStudentModal" tabindex="-1" aria-labelledby="addStudentModalLabel" aria-hidden="true">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <h5 class="modal-title" id="addStudentModalLabel">增加考生</h5>
                                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                                </div>
                                <div class="modal-body">
                                    <form id="add-student-form">
                                        <div class="mb-3">
                                            <label for="idnumber" class="form-label">学号</label>
                                            <input type="text" class="form-control" id="idnumber" required>
                                        </div>
                                        <div class="mb-3">
                                            <label for="name" class="form-label">姓名</label>
                                            <input type="text" class="form-control" id="name" required>
                                        </div>
                                        <div class="mb-3">
                                            <label for="examnumber" class="form-label">考号</label>
                                            <input type="text" class="form-control" id="examnumber" required>
                                        </div>
                                        <div class="mb-3">
                                            <label for="origin" class="form-label">生源地</label>
                                            <input type="text" class="form-control" id="origin">
                                        </div>
                                        <div class="mb-3">
                                            <label for="undergradmajor" class="form-label">本科专业</label>
                                            <input type="text" class="form-control" id="undergradmajor">
                                        </div>
                                        <div class="mb-3">
                                            <label for="undergradschool" class="form-label">本科学校</label>
                                            <input type="text" class="form-control" id="undergradschool">
                                        </div>
                                        <div class="mb-3">
                                            <label for="email" class="form-label">邮箱</label>
                                            <input type="email" class="form-control" id="email">
                                        </div>
                                        <div class="mb-3">
                                            <label for="phone" class="form-label">电话</label>
                                            <input type="text" class="form-control" id="phone">
                                        </div>
                                    </form>
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
                                    <button type="button" class="btn btn-primary" id="save-student-btn">保存</button>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!-- 编辑考生的模态框 -->
                    <div class="modal fade" id="editStudentModal" tabindex="-1" aria-labelledby="editStudentModalLabel" aria-hidden="true">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <h5 class="modal-title" id="editStudentModalLabel">编辑考生</h5>
                                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                                </div>
                                <div class="modal-body">
                                    <form id="edit-student-form">
                                        <input type="hidden" id="edit_idnumber">
                                        <div class="mb-3">
                                            <label for="edit_name" class="form-label">姓名</label>
                                            <input type="text" class="form-control" id="edit_name" required>
                                        </div>
                                        <div class="mb-3">
                                            <label for="edit_examnumber" class="form-label">考号</label>
                                            <input type="text" class="form-control" id="edit_examnumber" required>
                                        </div>
                                        <div class="mb-3">
                                            <label for="edit_origin" class="form-label">生源地</label>
                                            <input type="text" class="form-control" id="edit_origin">
                                        </div>
                                        <div class="mb-3">
                                            <label for="edit_undergradmajor" class="form-label">本科专业</label>
                                            <input type="text" class="form-control" id="edit_undergradmajor">
                                        </div>
                                        <div class="mb-3">
                                            <label for="edit_undergradschool" class="form-label">本科学校</label>
                                            <input type="text" class="form-control" id="edit_undergradschool">
                                        </div>
                                        <div class="mb-3">
                                            <label for="edit_email" class="form-label">邮箱</label>
                                            <input type="email" class="form-control" id="edit_email">
                                        </div>
                                        <div class="mb-3">
                                            <label for="edit_phone" class="form-label">电话</label>
                                            <input type="text" class="form-control" id="edit_phone">
                                        </div>
                                    </form>
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
                                    <button type="button" class="btn btn-primary" id="update-student-btn">保存更改</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="tab-pane fade" id="scores" role="tabpanel" aria-labelledby="scores-tab">
                    <h2>考生初试信息</h2>
                    <div class="d-flex justify-content-between mb-3">
                        <button class="btn btn-success" id="add-firstscore-btn" data-bs-toggle="modal" data-bs-target="#addFirstScoreModal">增加考生初试信息</button>
                        <input type="text" id="search-input-firstscore" class="form-control w-50" placeholder="搜索考生姓名获取其初试信息...">
                    </div>
                    <div class="card">
                        <div class="card-body">
                            <table class="table table-striped table-bordered">
                                <thead>
                                    <tr>
                                        <th>考号</th>
                                        <th>姓名</th>
                                        <th>英语</th>
                                        <th>数学</th>
                                        <th>专业课</th>
                                        <th>政治</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody id="scores-table-body">
                                    <!-- 示例一行 -->
                                     <tr data-examnumber="${score.examnumber}"
                                        data-name="${score.name}"
                                        data-englishscore="${score.englishscore}"
                                        data-mathscore="${score.mathscore}"
                                        data-majorscore="${score.majorscore}"
                                        data-politicalscore="${score.politicalscore}">
                                        <td>${score.examnumber}</td>
                                        <td>${score.name}</td>
                                        <td>${score.englishscore}</td>
                                        <td>${score.mathscore}</td>
                                        <td>${score.majorscore}</td>
                                        <td>${score.politicalscore}</td>
                                        <td>
                                            <button class="btn btn-warning btn-sm" onclick="editFirstScore(this)">修改</button>
                                            <button class="btn btn-danger btn-sm" onclick="deleteFirstScore('${score.examnumber}')">删除</button>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <!-- 增加初试成绩的模态框 -->
                    <div class="modal fade" id="addFirstScoreModal" tabindex="-1" aria-labelledby="addFirstScoreModalLabel" aria-hidden="true">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <h5 class="modal-title" id="addFirstScoreModalLabel">增加初试成绩</h5>
                                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                                </div>
                                <div class="modal-body">
                                    <form id="add-first-score-form">
                                        <div class="mb-3">
                                            <label for="add-first-score-examnumber" class="form-label">考号</label>
                                            <input type="text" class="form-control" id="add-first-score-examnumber" required>
                                        </div>
                                        <div class="mb-3">
                                            <label for="add-first-score-mathscore" class="form-label">数学成绩</label>
                                            <input type="text" class="form-control" id="add-first-score-mathscore" required>
                                        </div>
                                        <div class="mb-3">
                                            <label for="add-first-score-englishscore" class="form-label">英语成绩</label>
                                            <input type="text" class="form-control" id="add-first-score-englishscore" required>
                                        </div>
                                        <div class="mb-3">
                                            <label for="add-first-score-majorscore" class="form-label">专业成绩</label>
                                            <input type="text" class="form-control" id="add-first-score-majorscore" required>
                                        </div>
                                        <div class="mb-3">
                                            <label for="add-first-score-politicalscore" class="form-label">政治成绩</label>
                                            <input type="text" class="form-control" id="add-first-score-politicalscore" required>
                                        </div>
                                    </form>
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
                                    <button type="button" class="btn btn-primary" id="save-add-first-score-btn">保存</button>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!-- 编辑初试成绩的模态框 -->
                    <div class="modal fade" id="editFirstScoreModal" tabindex="-1" aria-labelledby="editFirstScoreModalLabel" aria-hidden="true">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <h5 class="modal-title" id="editFirstScoreModalLabel">编辑初试成绩</h5>
                                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                                </div>
                                <div class="modal-body">
                                    <form id="edit-first-score-form">
                                        <input type="hidden" id="edit-first-score-examnumber">
                                        <div class="mb-3">
                                            <label for="edit-first-score-mathscore" class="form-label">数学成绩</label>
                                            <input type="text" class="form-control" id="edit-first-score-mathscore" required>
                                        </div>
                                        <div class="mb-3">
                                            <label for="edit-first-score-englishscore" class="form-label">英语成绩</label>
                                            <input type="text" class="form-control" id="edit-first-score-englishscore" required>
                                        </div>
                                        <div class="mb-3">
                                            <label for="edit-first-score-majorscore" class="form-label">专业成绩</label>
                                            <input type="text" class="form-control" id="edit-first-score-majorscore" required>
                                        </div>
                                        <div class="mb-3">
                                            <label for="edit-first-score-politicalscore" class="form-label">政治成绩</label>
                                            <input type="text" class="form-control" id="edit-first-score-politicalscore" required>
                                        </div>
                                    </form>
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
                                    <button type="button" class="btn btn-primary" id="update-first-score-btn">保存更改</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="tab-pane fade" id="interviews" role="tabpanel" aria-labelledby="interviews-tab">
                    <h2>考生复试信息</h2>
                    <div class="d-flex justify-content-between mb-3">
                        <button class="btn btn-success" id="add-secondscore-btn" data-bs-toggle="modal" data-bs-target="#addSecondScoreModal">增加考生复试信息</button>
                        <input type="text" id="search-input-secondscore" class="form-control w-50" placeholder="搜索考生姓名获取其复试信息...">
                    </div>
                    <div class="card">
                        <div class="card-body">
                            <table class="table table-striped table-bordered">
                                <thead>
                                    <tr>
                                        <th>考号</th>
                                        <th>姓名</th>
                                        <th>英语复试</th>
                                        <th>专业知识复试</th>
                                        <th>综合素质复试</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody id="interviews-table-body">
                                </tbody>
                            </table>
                        </div>
                    </div>

                    <!-- 增加复试成绩的模态框 -->
                    <div class="modal fade" id="addSecondScoreModal" tabindex="-1" aria-labelledby="addSecondScoreModalLabel" aria-hidden="true">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <h5 class="modal-title" id="addSecondScoreModalLabel">增加复试成绩</h5>
                                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                                </div>
                                <div class="modal-body">
                                    <form id="add-second-score-form">
                                        <div class="mb-3">
                                            <label for="second-score-examnumber" class="form-label">考号</label>
                                            <input type="text" class="form-control" id="second-score-examnumber" required>
                                        </div>
                                        <div class="mb-3">
                                            <label for="second-score-englishskills" class="form-label">英语复试成绩</label>
                                            <input type="text" class="form-control" id="second-score-englishskills" required>
                                        </div>
                                        <div class="mb-3">
                                            <label for="second-score-majorknowledge" class="form-label">专业知识复试成绩</label>
                                            <input type="text" class="form-control" id="second-score-majorknowledge" required>
                                        </div>
                                        <div class="mb-3">
                                            <label for="second-score-overallquality" class="form-label">综合素质复试成绩</label>
                                            <input type="text" class="form-control" id="second-score-overallquality" required>
                                        </div>
                                    </form>
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
                                    <button type="button" class="btn btn-primary" id="save-second-score-btn">保存</button>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!-- 编辑复试成绩的模态框 -->
                    <!-- 编辑复试成绩的模态框 -->
                    <div class="modal fade" id="editSecondScoreModal" tabindex="-1" aria-labelledby="editSecondScoreModalLabel" aria-hidden="true">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <h5 class="modal-title" id="editSecondScoreModalLabel">编辑复试成绩</h5>
                                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                                </div>
                                <div class="modal-body">
                                    <form id="edit-second-score-form">
                                        <input type="hidden" id="edit-second-score-examnumber">
                                        <div class="mb-3">
                                            <label for="edit-second-score-englishskills" class="form-label">英语复试成绩</label>
                                            <input type="text" class="form-control" id="edit-second-score-englishskills" required>
                                        </div>
                                        <div class="mb-3">
                                            <label for="edit-second-score-majorknowledge" class="form-label">专业知识复试成绩</label>
                                            <input type="text" class="form-control" id="edit-second-score-majorknowledge" required>
                                        </div>
                                        <div class="mb-3">
                                            <label for="edit-second-score-overallquality" class="form-label">综合素质复试成绩</label>
                                            <input type="text" class="form-control" id="edit-second-score-overallquality" required>
                                        </div>
                                    </form>
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
                                    <button type="button" class="btn btn-primary" id="update-second-score-btn">保存更改</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="tab-pane fade" id="stutea" role="tabpanel" aria-labelledby="stutea-tab">
                    <h2>师生双向选择信息</h2>
                    <div class="card">
                        <div class="card-body">
                            <table class="table table-striped table-bordered" id="stutea-table">
                                <thead>
                                    <tr>
                                        <th>考号</th>
                                        <th>导师ID</th>
                                        <th>当前意向</th>
                                        <th>状态</th>
                                    </tr>
                                </thead>
                                <tbody id="stutea-table-body">
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>

                <div class="tab-pane fade" id="supervisors" role="tabpanel" aria-labelledby="supervisors-tab">
                    <h2>导师信息</h2>
                    <div class="d-flex justify-content-between mb-3">
                        <button class="btn btn-success" id="add-supervisor-btn" data-bs-toggle="modal" data-bs-target="#addSupervisorModal">增加导师</button>
                        <input type="text" id="search-input-supervisor" class="form-control w-50" placeholder="搜索导师...">
                    </div>
                    <div class="card">
                        <div class="card-body">
                            <table class="table table-striped table-bordered">
                                <thead>
                                    <tr>
                                        <th>导师ID</th>
                                        <th>姓名</th>
                                        <th>简介</th>
                                        <th>邮箱</th>
                                        <th>电话</th>
                                        <th>教授学科</th>
                                        <th>导师类型</th>
                                        <th>导师职称</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody id="supervisors-table-body">
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <!-- 增加导师的模态框 -->
                    <div class="modal fade" id="addSupervisorModal" tabindex="-1" aria-labelledby="addSupervisorModalLabel" aria-hidden="true">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <h5 class="modal-title" id="addSupervisorModalLabel">增加导师</h5>
                                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                                </div>
                                <div class="modal-body">
                                    <form id="add-supervisor-form">
                                        <div class="mb-3">
                                            <label for="instructorid" class="form-label">导师ID</label>
                                            <input type="text" class="form-control" id="instructorid" required>
                                        </div>
                                        <div class="mb-3">
                                            <label for="instructorname" class="form-label">姓名</label>
                                            <input type="text" class="form-control" id="instructorname" required>
                                        </div>
                                        <div class="mb-3">
                                            <label for="instructorbio" class="form-label">简介</label>
                                            <textarea class="form-control" id="instructorbio"></textarea>
                                        </div>
                                        <div class="mb-3">
                                            <label for="instructoremail" class="form-label">邮箱</label>
                                            <input type="email" class="form-control" id="instructoremail">
                                        </div>
                                        <div class="mb-3">
                                            <label for="instructorphone" class="form-label">电话</label>
                                            <input type="text" class="form-control" id="instructorphone">
                                        </div>
                                        <div class="mb-3">
                                            <label for="instructorsubject" class="form-label">教授学科</label>
                                            <input type="text" class="form-control" id="instructorsubject">
                                        </div>
                                        <div class="mb-3">
                                            <label for="instructortype" class="form-label">导师类型</label>
                                            <input type="text" class="form-control" id="instructortype">
                                        </div>
                                        <div class="mb-3">
                                            <label for="instructortitle" class="form-label">导师职称</label>
                                            <input type="text" class="form-control" id="instructortitle">
                                        </div>
                                    </form>
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
                                    <button type="button" class="btn btn-primary" id="save-supervisor-btn">保存</button>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!-- 编辑导师的模态框 -->
                    <div class="modal fade" id="editSupervisorModal" tabindex="-1" aria-labelledby="editSupervisorModalLabel" aria-hidden="true">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <h5 class="modal-title" id="editSupervisorModalLabel">编辑导师</h5>
                                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                                </div>
                                <div class="modal-body">
                                    <form id="edit-supervisor-form">
                                        <input type="hidden" id="edit_instructorid">
                                        <div class="mb-3">
                                            <label for="edit_instructorname" class="form-label">姓名</label>
                                            <input type="text" class="form-control" id="edit_instructorname" required>
                                        </div>
                                        <div class="mb-3">
                                            <label for="edit_instructorbio" class="form-label">简介</label>
                                            <textarea class="form-control" id="edit_instructorbio"></textarea>
                                        </div>
                                        <div class="mb-3">
                                            <label for="edit_instructoremail" class="form-label">邮箱</label>
                                            <input type="email" class="form-control" id="edit_instructoremail">
                                        </div>
                                        <div class="mb-3">
                                            <label for="edit_instructorphone" class="form-label">电话</label>
                                            <input type="text" class="form-control" id="edit_instructorphone">
                                        </div>
                                        <div class="mb-3">
                                            <label for="edit_instructorsubject" class="form-label">教授学科</label>
                                            <input type="text" class="form-control" id="edit_instructorsubject">
                                        </div>
                                        <div class="mb-3">
                                            <label for="edit_instructortype" class="form-label">导师类型</label>
                                            <input type="text" class="form-control" id="edit_instructortype">
                                        </div>
                                        <div class="mb-3">
                                            <label for="edit_instructortitle" class="form-label">导师职称</label>
                                            <input type="text" class="form-control" id="edit_instructortitle">
                                        </div>
                                    </form>
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
                                    <button type="button" class="btn btn-primary" id="update-supervisor-btn">保存更改</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
         let currentPage = 1; // 当前页面
    const rowsPerPage = 10; // 每页的行数

    // 加载考生信息并初始化分页
    fetch('http://127.0.0.1:8000/stu')
        .then(response => response.json())
        .then(data => {
            const studentsData = data.students_info; // 存储所有的学生数据
            displayTable(studentsData, currentPage); // 初始显示第一页
        })
        .catch(error => console.error('Error:', error));

    function displayTable(data, page) {
        const studentsTableBody = document.getElementById('students-table-body');
        studentsTableBody.innerHTML = '';

        const startIndex = (page - 1) * rowsPerPage;
        const endIndex = Math.min(startIndex + rowsPerPage, data.length);

        for (let i = startIndex; i < endIndex; i++) {
            const student = data[i];
            const row = document.createElement('tr');
            row.innerHTML = `
                <td>${student.idnumber}</td>
                <td>${student.name}</td>
                <td>${student.examnumber}</td>
                <td>${student.origin}</td>
                <td>${student.undergradmajor}</td>
                <td>${student.undergradschool}</td>
                <td>${student.email}</td>
                <td>${student.phone}</td>
                <td>
                    <button class="btn btn-warning btn-sm" onclick="editStudent('${student.idnumber}')">修改</button>
                    <button class="btn btn-danger btn-sm" onclick="deleteStudent('${student.idnumber}')">删除</button>
                </td>
            `;
            studentsTableBody.appendChild(row);
        }

        setupPagination(data.length);
    }

    function setupPagination(totalRows) {
        const paginationContainer = document.getElementById('pagination');
        paginationContainer.innerHTML = '';

        const pageCount = Math.ceil(totalRows / rowsPerPage);

        for (let i = 1; i <= pageCount; i++) {
            const pageButton = document.createElement('button');
            pageButton.innerText = i;
            pageButton.className = 'btn btn-secondary me-2';
            pageButton.onclick = () => {
                currentPage = i;
                displayTable(data.students_info, currentPage); // 重新显示当前页面的数据
            };
            paginationContainer.appendChild(pageButton);
        }
    }
            const sections = document.querySelectorAll('.tab-pane');
        const links = document.querySelectorAll('.nav-link');

        links.forEach(link => {
            link.addEventListener('click', (e) => {
                e.preventDefault();
                const sectionId = link.getAttribute('data-section');
                sections.forEach(section => {
                    if (section.id === sectionId) {
                        section.classList.add('show', 'active');
                    } else {
                        section.classList.remove('show', 'active');
                    }
                });
            });
        });

        // 初始化页面加载时显示学科信息
        const subjectsTab = document.getElementById('subjects-tab');
        subjectsTab.click();

        // 获取学科信息
    fetch('http://127.0.0.1:8000/sub')
        .then(response => response.json())
        .then(data => {
            const subjectsTableBody = document.getElementById('subjects-table-body');
            subjectsTableBody.innerHTML = ''; // 清空表格内容

            // 添加搜索功能的事件监听器
            const searchInput = document.getElementById('search-input');
            searchInput.addEventListener('input', () => {
                const searchTerm = searchInput.value.toLowerCase();
                const rows = subjectsTableBody.querySelectorAll('tr');
                rows.forEach(row => {
                    const subjectName = row.querySelector('td:nth-child(2)').textContent.toLowerCase();
                    row.style.display = subjectName.includes(searchTerm) ? '' : 'none';
                });
            });

            data.subjects_info.forEach(subject => {
                const row = document.createElement('tr');
                row.innerHTML = `
                <td>${subject.subject_id}</td>
                <td>${subject.subject_name}</td>
                <td>${subject.subject_level}</td>
                <td>${subject.parent_subject}</td>
                <td>${subject.subject_overview}</td>
                <td>${subject.subject_type}</td>
                <td>
                    <button class="btn btn-warning btn-sm" onclick="editSubject('${subject.subject_id}')">修改</button>
                    <button class="btn btn-danger btn-sm" onclick="deleteSubject('${subject.subject_id}')">删除</button>
                </td>
            `;
                subjectsTableBody.appendChild(row);
            });
        })
        .catch(error => console.error('Error:', error));

    // 添加学科
    document.getElementById('save-subject-btn').addEventListener('click', () => {
        const subjectId = document.getElementById('subject_id').value;
        const subjectName = document.getElementById('subject_name').value;
        const subjectLevel = document.getElementById('subject_level').value;
        const parentSubject = document.getElementById('parent_subject').value;
        const subjectOverview = document.getElementById('subject_overview').value;
        const subjectType = document.getElementById('subject_type').value;

        fetch('http://127.0.0.1:8000/add_subject/', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify({
                subject_id: subjectId,
                subject_name: subjectName,
                subject_level: subjectLevel,
                parent_subject: parentSubject,
                subject_overview: subjectOverview,
                subject_type: subjectType,
            }),
        })
        .then(response => response.json())
        .then(data => {
            alert("科目已添加!");
            location.reload(); // Reload to see new subject
        })
        .catch(error => console.error('Error:', error));
    });

    function deleteSubject(subjectId) {
    console.log(subjectId)
    if (confirm("您确定要删除这个科目吗?")) {
        fetch(`http://127.0.0.1:8000/delete_subject/${subjectId}/`, { method: 'DELETE' })
            .then(response => {
                if (!response.ok) {
                    throw new Error('Network response was not ok');
                }
                return response.json();
            })
            .then(data => {
                alert("科目已删除!");
            })
            .catch(error => console.error('Error:', error));
            location.reload();
    }
}

    function editSubject(subjectId) {
    // 获取当前科目的数据
    console.log(subjectId)
    fetch(`http://127.0.0.1:8000/get_subject/${subjectId}/`)
    .then(response => {
        if (!response.ok) {
            throw new Error('Subject not found. Please check the ID.'); // 更具体的错误处理
        }
        return response.json();
    })
    .then(data => {
        // 填充模态框的输入字段
        document.getElementById('edit_subject_name').value = data.subject_name;
        document.getElementById('edit_subject_level').value = data.subject_level;
        document.getElementById('edit_parent_subject').value = data.parent_subject;
        document.getElementById('edit_subject_overview').value = data.subject_overview;
        document.getElementById('edit_subject_type').value = data.subject_type;
        // 这里还需要设置隐藏字段
        document.getElementById('edit_subject_id').value = subjectId; // 这一行是关键

        // 显示模态框
        var editModal = new bootstrap.Modal(document.getElementById('editSubjectModal'));
        editModal.show();
    })
    .catch(error => {
        console.error('Error:', error);
        alert(error.message); // 提示用户
    });
}

    // 更新科目的请求
    document.getElementById('update-subject-btn').addEventListener('click', () => {
        const subjectId = document.getElementById('edit_subject_id').value; // 确保 ID 是从隐藏字段获取的
        const subjectName = document.getElementById('edit_subject_name').value;
        const subjectLevel = document.getElementById('edit_subject_level').value;
        const parentSubject = document.getElementById('edit_parent_subject').value;
        const subjectOverview = document.getElementById('edit_subject_overview').value;
        const subjectType = document.getElementById('edit_subject_type').value;

        fetch(`http://127.0.0.1:8000/edit_subject/${subjectId}/`, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify({
                subject_name: subjectName,
                subject_level: subjectLevel,
                parent_subject: parentSubject,
                subject_overview: subjectOverview,
                subject_type: subjectType,
            }),
        })
        .then(response => {
            if (!response.ok) {
                throw new Error('Network response was not ok');
            }
            return response.json();
        })
        .then(data => {
            alert("科目已更新!");
            location.reload(); // Reload page to see updated data
        })
        .catch(error => console.error('Error:', error));
    });


    // 加载考生信息
    fetch('http://127.0.0.1:8000/stu')
        .then(response => response.json())
        .then(data => {
            const studentsTableBody = document.getElementById('students-table-body');
            studentsTableBody.innerHTML = '';

            data.students_info.forEach(student => {
                const row = document.createElement('tr');
                row.innerHTML = `
                    <td>${student.idnumber}</td>
                    <td>${student.name}</td>
                    <td>${student.examnumber}</td>
                    <td>${student.origin}</td>
                    <td>${student.undergradmajor}</td>
                    <td>${student.undergradschool}</td>
                    <td>${student.email}</td>
                    <td>${student.phone}</td>
                    <td>
                        <button class="btn btn-warning btn-sm" onclick="editStudent('${student.idnumber}')">修改</button>
                        <button class="btn btn-danger btn-sm" onclick="deleteStudent('${student.idnumber}')">删除</button>
                    </td>
                `;
                studentsTableBody.appendChild(row);
            });

            // 搜索功能的事件监听器
            const searchInput = document.getElementById('search-input-student'); // 获取搜索框
            searchInput.addEventListener('input', () => {
                const searchTerm = searchInput.value.toLowerCase();
                const rows = studentsTableBody.querySelectorAll('tr'); // 获取表格里的所有行
                rows.forEach(row => {
                    const studentName = row.querySelector('td:nth-child(2)').textContent.toLowerCase(); // 取出姓名的格
                    row.style.display = studentName.includes(searchTerm) ? '' : 'none'; // 判断是否包含
                });
            });
        })
        .catch(error => console.error('Error:', error));
    // 添加学生
    document.getElementById('save-student-btn').addEventListener('click', () => {
        const idnumber = document.getElementById('idnumber').value;
        const name = document.getElementById('name').value;
        const examnumber = document.getElementById('examnumber').value;
        const origin = document.getElementById('origin').value;
        const undergradmajor = document.getElementById('undergradmajor').value;
        const undergradschool = document.getElementById('undergradschool').value;
        const email = document.getElementById('email').value;
        const phone = document.getElementById('phone').value;

        fetch('http://127.0.0.1:8000/add_student/', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify({
                idnumber,
                name,
                examnumber,
                origin,
                undergradmajor,
                undergradschool,
                email,
                phone,
            }),
        })
        .then(response => response.json())
        .then(data => {
            alert("学生已添加!");
            location.reload(); // Reload to see new student
        })
        .catch(error => console.error('Error:', error));
    });

    // 编辑学生
    function editStudent(idnumber) {
        fetch(`http://127.0.0.1:8000/get_student/${idnumber}/`)
        .then(response => {
            if (!response.ok) {
                throw new Error('学生未找到');
            }
            return response.json();
        })
        .then(data => {
            document.getElementById('edit_idnumber').value = idnumber;
            document.getElementById('edit_name').value = data.name;
            document.getElementById('edit_examnumber').value = data.examnumber;
            document.getElementById('edit_origin').value = data.origin;
            document.getElementById('edit_undergradmajor').value = data.undergradmajor;
            document.getElementById('edit_undergradschool').value = data.undergradschool;
            document.getElementById('edit_email').value = data.email;
            document.getElementById('edit_phone').value = data.phone;

            var editModal = new bootstrap.Modal(document.getElementById('editStudentModal'));
            editModal.show();
        })
        .catch(error => console.error('Error:', error));
    }

    // 更新学生信息
    document.getElementById('update-student-btn').addEventListener('click', () => {
        const idnumber = document.getElementById('edit_idnumber').value;
        const name = document.getElementById('edit_name').value;
        const examnumber = document.getElementById('edit_examnumber').value;
        const origin = document.getElementById('edit_origin').value;
        const undergradmajor = document.getElementById('edit_undergradmajor').value;
        const undergradschool = document.getElementById('edit_undergradschool').value;
        const email = document.getElementById('edit_email').value;
        const phone = document.getElementById('edit_phone').value;

        fetch(`http://127.0.0.1:8000/edit_student/${idnumber}/`, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify({
                name,
                examnumber,
                origin,
                undergradmajor,
                undergradschool,
                email,
                phone,
            }),
        })
        .then(response => {
            if (!response.ok) {
                throw new Error('请求失败');
            }
            return response.json();
        })
        .then(data => {
            alert("学生已更新!");
            location.reload();
        })
        .catch(error => console.error('Error:', error));
    });

    // 删除学生
    function deleteStudent(idnumber) {
        if (confirm("您确定要删除这个考生吗?")) {
            fetch(`http://127.0.0.1:8000/delete_student/${idnumber}/`, { method: 'DELETE' })
                .then(response => {
                    if (!response.ok) {
                        throw new Error('网络响应出错');
                    }
                    return response.json();
                })
                .then(data => {
                    alert("学生已删除!");
                })
                .catch(error => console.error('Error:', error));
                location.reload();
        }
    }
    // 加载导师信息
    fetch('http://127.0.0.1:8000/tea')
        .then(response => response.json())
        .then(data => {
        console.log(data)
            const supervisorsTableBody = document.getElementById('supervisors-table-body');
            supervisorsTableBody.innerHTML = '';
            data.teachers_info.forEach(teacher => {
                const row = document.createElement('tr');
                row.innerHTML = `
                    <td>${teacher.instructorid}</td>
                    <td>${teacher.instructorname}</td>
                    <td>${teacher.instructorbio}</td>
                    <td>${teacher.instructoremail}</td>
                    <td>${teacher.instructorphone}</td>
                    <td>${teacher.instructorsubject}</td>
                    <td>${teacher.instructortype}</td>
                    <td>${teacher.instructortitle}</td>
                    <td>
                        <button class="btn btn-warning btn-sm" onclick="editTeacher('${teacher.instructorid}')">修改</button>
                        <button class="btn btn-danger btn-sm" onclick="deleteTeacher('${teacher.instructorid}')">删除</button>
                    </td>
                `;
                supervisorsTableBody.appendChild(row);
            });

            // 添加搜索功能的事件监听器
            const searchInput = document.getElementById('search-input-supervisor'); // 获取搜索框
            searchInput.addEventListener('input', () => {
                const searchTerm = searchInput.value.toLowerCase();
                const rows = supervisorsTableBody.querySelectorAll('tr');
                rows.forEach(row => {
                    const instructorName = row.querySelector('td:nth-child(2)').textContent.toLowerCase();
                    row.style.display = instructorName.includes(searchTerm) ? '' : 'none';
                });
            });
        })
        .catch(error => console.error('Error:', error));

    // 添加导师
    document.getElementById('save-supervisor-btn').addEventListener('click', () => {
        const instructorid = document.getElementById('instructorid').value;
        const instructorname = document.getElementById('instructorname').value;
        const instructorbio = document.getElementById('instructorbio').value;
        const instructoremail = document.getElementById('instructoremail').value;
        const instructorphone = document.getElementById('instructorphone').value;
        const instructorsubject = document.getElementById('instructorsubject').value;
        const instructortype = document.getElementById('instructortype').value;
        const instructortitle = document.getElementById('instructortitle').value;

        fetch('http://127.0.0.1:8000/add_teacher/', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify({
                instructorid,
                instructorname,
                instructorbio,
                instructoremail,
                instructorphone,
                instructorsubject,
                instructortype,
                instructortitle,
            }),
        })
        .then(response => response.json())
        .then(data => {
            alert("导师已添加!");
            location.reload(); // Reload to see new teacher
        })
        .catch(error => console.error('Error:', error));
    });

    // 编辑导师
    function editTeacher(instructorid) {
        fetch(`http://127.0.0.1:8000/get_teacher/${instructorid}/`)
        .then(response => {
            if (!response.ok) {
                throw new Error('导师未找到');
            }
            return response.json();
        })
        .then(data => {
            document.getElementById('edit_instructorid').value = instructorid;
            document.getElementById('edit_instructorname').value = data.instructorname;
            document.getElementById('edit_instructorbio').value = data.instructorbio;
            document.getElementById('edit_instructoremail').value = data.instructoremail;
            document.getElementById('edit_instructorphone').value = data.instructorphone;
            document.getElementById('edit_instructorsubject').value = data.instructorsubject;
            document.getElementById('edit_instructortype').value = data.instructortype;
            document.getElementById('edit_instructortitle').value = data.instructortitle;

            var editModal = new bootstrap.Modal(document.getElementById('editSupervisorModal'));
            editModal.show();
        })
        .catch(error => console.error('Error:', error));
    }

    // 更新导师信息
    document.getElementById('update-supervisor-btn').addEventListener('click', () => {
        const instructorid = document.getElementById('edit_instructorid').value;
        const instructorname = document.getElementById('edit_instructorname').value;
        const instructorbio = document.getElementById('edit_instructorbio').value;
        const instructoremail = document.getElementById('edit_instructoremail').value;
        const instructorphone = document.getElementById('edit_instructorphone').value;
        const instructorsubject = document.getElementById('edit_instructorsubject').value;
        const instructortype = document.getElementById('edit_instructortype').value;
        const instructortitle = document.getElementById('edit_instructortitle').value;

        fetch(`http://127.0.0.1:8000/edit_teacher/${instructorid}/`, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify({
                instructorname,
                instructorbio,
                instructoremail,
                instructorphone,
                instructorsubject,
                instructortype,
                instructortitle,
            }),
        })
        .then(response => {
            if (!response.ok) {
                throw new Error('请求失败');
            }
            return response.json();
        })
        .then(data => {
            alert("导师已更新!");
            location.reload(); // Reload to see updated data
        })
        .catch(error => console.error('Error:', error));
    });

    // 删除导师
    function deleteTeacher(instructorid) {
        if (confirm("您确定要删除这个导师吗?")) {
            fetch(`http://127.0.0.1:8000/delete_teacher/${instructorid}/`, { method: 'DELETE' })
                .then(response => {
                    if (!response.ok) {
                        throw new Error('网络响应出错');
                    }
                    return response.json();
                })
                .then(data => {
                    alert("导师已删除!");
                })
                .catch(error => console.error('Error:', error));
                location.reload();
        }
    }
    // 加载师生双向选择信息
fetch('http://127.0.0.1:8000/stutea')
    .then(response => response.json())
    .then(data => {
        const stuteaTableBody = document.getElementById('stutea-table-body');
        stuteaTableBody.innerHTML = '';
        data.stuteas_info.forEach(stutea => {
            const row = document.createElement('tr');
            row.innerHTML = `
                <td>${stutea.examnumber}</td>
                <td>${stutea.instructorid}</td>
                <td>${stutea.current_wish}</td>
                <td>${stutea.status}</td>
            `;
            stuteaTableBody.appendChild(row);
        });
    })
    .catch(error => console.error('Error:', error));

       // 加载考生初试信息
    fetch('http://127.0.0.1:8000/fir')
    .then(response => response.json())
    .then(data => {
        const scoresTableBody = document.getElementById('scores-table-body');
        scoresTableBody.innerHTML = '';
        data.firstscores_info.forEach(score => {
            const row = document.createElement('tr');
            row.setAttribute('data-examnumber', score.examnumber);
            row.setAttribute('data-name', score.name);
            row.setAttribute('data-englishscore', score.englishscore);
            row.setAttribute('data-mathscore', score.mathscore);
            row.setAttribute('data-majorscore', score.majorscore);
            row.setAttribute('data-politicalscore', score.politicalscore);
            row.innerHTML = `
                <td>${score.examnumber}</td>
                <td>${score.name}</td>
                <td>${score.englishscore}</td>
                <td>${score.mathscore}</td>
                <td>${score.majorscore}</td>
                <td>${score.politicalscore}</td>
                <td>
                    <button class="btn btn-warning btn-sm" onclick="editFirstScore(this)">修改</button>
                    <button class="btn btn-danger btn-sm" onclick="deleteFirstScore('${score.examnumber}')">删除</button>
                </td>
            `;
            scoresTableBody.appendChild(row);
        });

        // 添加搜索功能的事件监听器
        const searchInput = document.getElementById('search-input-firstscore'); // 获取搜索框
        searchInput.addEventListener('input', () => {
            const searchTerm = searchInput.value.toLowerCase();
            const rows = scoresTableBody.querySelectorAll('tr');
            rows.forEach(row => {
                const stu_fir_name = row.querySelector('td:nth-child(2)').textContent.toLowerCase();
                row.style.display = stu_fir_name.includes(searchTerm) ? '' : 'none';
            });
        });
    })
    .catch(error => console.error('Error:', error));

    // 加载考生复试信息
    fetch('http://127.0.0.1:8000/sec')
    .then(response => response.json())
    .then(data => {
        const interviewsTableBody = document.getElementById('interviews-table-body');
        interviewsTableBody.innerHTML = '';
        data.secondscores_info.forEach(interview => {
            const row = document.createElement('tr');
            row.setAttribute('data-examnumber', interview.examnumber);
            row.setAttribute('data-name', interview.name);
            row.setAttribute('data-englishskills', interview.englishskills);
            row.setAttribute('data-majorknowledge', interview.majorknowledge);
            row.setAttribute('data-overallquality', interview.overallquality);
            row.innerHTML = `
                <td>${interview.examnumber}</td>
                <td>${interview.name}</td>
                <td>${interview.englishskills}</td>
                <td>${interview.majorknowledge}</td>
                <td>${interview.overallquality}</td>
                <td>
                    <button class="btn btn-warning btn-sm" onclick="editSecondScore(this)">修改</button>
                    <button class="btn btn-danger btn-sm" onclick="deleteSecondScore('${interview.examnumber}')">删除</button>                </td>
            `;
            interviewsTableBody.appendChild(row);
        });

        // 添加搜索功能的事件监听器
        const searchInput = document.getElementById('search-input-secondscore'); // 获取搜索框
        searchInput.addEventListener('input', () => {
            const searchTerm = searchInput.value.toLowerCase();
            const rows = interviewsTableBody.querySelectorAll('tr');
            rows.forEach(row => {
                const stu_sec_name = row.querySelector('td:nth-child(2)').textContent.toLowerCase();
                row.style.display = stu_sec_name.includes(searchTerm) ? '' : 'none';
            });
        });
    })
    .catch(error => console.error('Error:', error));
        // 添加初试成绩
        document.getElementById('save-add-first-score-btn').addEventListener('click', () => {
            const examnumber = document.getElementById('add-first-score-examnumber').value;
            const mathscore = document.getElementById('add-first-score-mathscore').value;
            const englishscore = document.getElementById('add-first-score-englishscore').value;
            const majorscore = document.getElementById('add-first-score-majorscore').value;
            const politicalscore = document.getElementById('add-first-score-politicalscore').value;
            console.log(examnumber);
            fetch('http://127.0.0.1:8000/add_firstscore/', {
                method:'POST',
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify({
                    examnumber,
                    mathscore,
                    englishscore,
                    majorscore,
                    politicalscore,
                }),
            })
            .then(response => response.json())
            .then(data => {
                alert("初试成绩已添加!");
                location.reload(); // Reload to see new first score
            })
            .catch(error => console.error('Error:', error));
        });

        // 添加复试成绩
        document.getElementById('save-second-score-btn').addEventListener('click', () => {
            const examnumber = document.getElementById('second-score-examnumber').value;
            const englishskills = document.getElementById('second-score-englishskills').value;
            const majorknowledge = document.getElementById('second-score-majorknowledge').value;
            const overallquality = document.getElementById('second-score-overallquality').value;

            fetch('http://127.0.0.1:8000/add_secondscore/', {
                method:'POST',
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify({
                    examnumber,
                    englishskills,
                    majorknowledge,
                    overallquality,
                }),
            })
            .then(response => response.json())
            .then(data => {
                alert("复试成绩已添加!");
                location.reload(); // Reload to see new second score
            })
            .catch(error => console.error('Error:', error));
        });
        //编辑初试信息
        function editFirstScore(button) {
            const row = button.closest('tr');

            const examnumber = row.getAttribute('data-examnumber');
            const englishscore = row.getAttribute('data-englishscore');
            const mathscore = row.getAttribute('data-mathscore');
            const majorscore = row.getAttribute('data-majorscore');
            const politicalscore = row.getAttribute('data-politicalscore');

            document.getElementById('edit-first-score-examnumber').value = examnumber;
            document.getElementById('edit-first-score-mathscore').value = mathscore;
            document.getElementById('edit-first-score-englishscore').value = englishscore;
            document.getElementById('edit-first-score-majorscore').value = majorscore;
            document.getElementById('edit-first-score-politicalscore').value = politicalscore;

            var editModal = new bootstrap.Modal(document.getElementById('editFirstScoreModal'));
            editModal.show();
        }
        // 更新初试成绩
        document.getElementById('update-first-score-btn').addEventListener('click', () => {
            const examnumber = document.getElementById('edit-first-score-examnumber').value; // 从输入框获取
            const englishscore = document.getElementById('edit-first-score-englishscore').value;
            const mathscore = document.getElementById('edit-first-score-mathscore').value;
            const majorscore = document.getElementById('edit-first-score-majorscore').value;
            const politicalscore = document.getElementById('edit-first-score-politicalscore').value;

            fetch(`http://127.0.0.1:8000/edit_firstscore/`, { // 不再在 URL 中加 examnumber
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify({
                    examnumber, // 将 examnumber 放到请求体中
                    englishscore,
                    mathscore,
                    majorscore,
                    politicalscore,
                }),
            })
            .then(response => {
                if (!response.ok) {
                    throw new Error('请求失败');
                }
                return response.json();
            })
            .then(data => {
                alert("初试成绩已更新!");
                location.reload(); // Reload to see updated data
            })
            .catch(error => console.error('Error:', error));
        });

        // 编辑复试成绩
        function editSecondScore(button) {
            const row = button.closest('tr');

            const examnumber = row.getAttribute('data-examnumber');
            const englishskills = row.getAttribute('data-englishskills');
            const majorknowledge = row.getAttribute('data-majorknowledge');
            const overallquality = row.getAttribute('data-overallquality');

            document.getElementById('edit-second-score-examnumber').value = examnumber;
            document.getElementById('edit-second-score-englishskills').value = englishskills;
            document.getElementById('edit-second-score-majorknowledge').value = majorknowledge;
            document.getElementById('edit-second-score-overallquality').value = overallquality;

            var editModal = new bootstrap.Modal(document.getElementById('editSecondScoreModal'));
            editModal.show();
        }

        // 更新复试成绩
        document.getElementById('update-second-score-btn').addEventListener('click', () => {
            const examnumber = document.getElementById('edit-second-score-examnumber').value;
            const englishskills = document.getElementById('edit-second-score-englishskills').value;
            const majorknowledge = document.getElementById('edit-second-score-majorknowledge').value;
            const overallquality = document.getElementById('edit-second-score-overallquality').value;

            fetch(`http://127.0.0.1:8000/edit_secondscore/`, {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify({
                    examnumber,
                    englishskills,
                    majorknowledge,
                    overallquality,
                }),
            })
            .then(response => {
                if (!response.ok) {
                    throw new Error('请求失败');
                }
                return response.json();
            })
            .then(data => {
                alert("复试成绩已更新!");
                location.reload(); // Reload to see updated data
            })
            .catch(error => console.error('Error:', error));
        });

        // 删除初试成绩
        function deleteFirstScore(examnumber) {
            if (confirm("您确定要删除这个初试成绩吗?")) {
                // 确保 URL 没有多余空格
                fetch(`http://127.0.0.1:8000/delete_firstscore/${examnumber}/`, {
                    method: 'DELETE',
                })
                .then(response => {
                    if (!response.ok) {
                        throw new Error('网络响应出错');
                    }
                    return response.json();
                })
                .then(data => {
                    alert("初试成绩已删除!");
                })
                .catch(error => console.error('Error:', error));
                location.reload();
            }
        }

        // 删除复试成绩
        function deleteSecondScore(examnumber) {
            if (confirm("您确定要删除这个复试成绩吗?")) {
                fetch(`http://127.0.0.1:8000/delete_secondscore/${examnumber}/`, {
                    method: 'DELETE',
                })
                .then(response => {
                    if (!response.ok) {
                        throw new Error('网络响应出错');
                    }
                    return response.json();
                })
                .then(data => {
                    alert("复试成绩已删除!");

                })
                .catch(error => console.error('Error:', error));
                location.reload();
            }
        }

</script>
</body>
</html>